<template>
  <div class="course">
    <div class="course-header">
      <div class="title">{{ datas.title }}</div>
      <div class="desc">{{ datas.desc }}</div>
    </div>
    <div class="course-body">
      <el-form :model="datas.form" size="small" label-width="82px">
        <!-- 板块名称选择 -->
        <el-form-item label="标题名称">
          <el-input
            v-model="datas.form.title"
            type="text"
            placeholder="请输入标题名称"
            size="small"
            maxlength="16"
            show-word-limit
          ></el-input>
        </el-form-item>

        <!-- 排列方式选择 -->
        <el-form-item label="展示方式">
          <el-radio-group v-model="datas.form.arrange_type">
            <el-radio
              v-for="item in arrangeOptions"
              :key="item.label"
              :label="item.label"
            >
              {{ item.title }}
            </el-radio>
          </el-radio-group>
        </el-form-item>

        <!-- 课程列数选择 -->
        <el-form-item v-if="datas.form.arrange_type == 1" label="列表样式">
          <el-radio-group v-model="datas.form.column">
            <el-radio
              v-for="item in columnOptions"
              :key="item.label"
              :label="item.label"
            >
              {{ item.title }}
            </el-radio>
          </el-radio-group>
        </el-form-item>

        <!-- 课程数量选择 -->
        <el-form-item label="展示课程数">
          <el-input-number
            v-model="datas.form.number"
            :min="1"
            :max="99"
            @change="handlerChangeNumber"
          ></el-input-number>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>

export default {
  name: 'IntentCourseStyle',
  props: {
    datas: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      arrangeOptions: [
        {
          label: 1,
          title: '宫格'
        },
        {
          label: 2,
          title: '滚动'
        }
      ],
      columnOptions: [
        {
          label: 2,
          title: '2列'
        },
        {
          label: 3,
          title: '3列'
        },
        {
          label: 4,
          title: '4列'
        }
      ]
    }
  },
  methods: {
    // 数量改变
    handlerChangeNumber() {
      this.setSourceIndex()
    },
    setSourceIndex() {
      if (this.$util.isUndef(this.datas.form.source_index)) {
        this.$set(this.datas.form, 'source_index', 0)
      }
      this.datas.form.source_index = Math.random()
    }
  }
}
</script>

<style scoped lang="scss">
.course {
  padding-top: 20px;
  padding-left: 24px;
  padding-right: 34px;

  &-header {
    padding-bottom: 10px;
    border-bottom: 1px solid #ebeef5;

    .title {
      font-size: 16px;
      font-weight: 500;
      color: #303133;
      line-height: 24px;
    }

    .desc {
      margin-top: 10px;
      font-size: 12px;
      font-weight: 400;
      color: #909399;
      line-height: 16px;
    }
  }

  &-body {
    margin-top: 20px;

    ::v-deep.el-radio {
      margin-right: 20px;

      &:last-child {
        margin-right: 0;
      }
    }
  }
}
</style>
